package inject;

import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;
import javax.swing.JTextField;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;

public class Inject extends JFrame{

    public Inject() {
        initUI();
    }
    
    public final void initUI() {
        
        try {
            UIManager.setLookAndFeel(
                UIManager.getSystemLookAndFeelClassName()
            );
        } catch (Exception e) {
            e.printStackTrace();
        }
        
        JTabbedPane tabWindow = new JTabbedPane();
        add(tabWindow);
        
        JPanel mainTab = new JPanel();
        JPanel saveTab = new JPanel();
        
        final JLabel errorLabel = new JLabel();
        JLabel testLabel = new JLabel("Url :");
        final JTextField urlInput = new JTextField("", 30);
        JButton submitUrl = new JButton("Submit");
        
        submitUrl.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                
                if(urlInput.getText().length() > 5) {
                    
                    System.out.println(
                            
                        //Website.getWebsiteOutput(urlInput.getText()).toString()
                            
                    );
                    
                    System.out.println("Replace url " + 
                        Website.findAndReplaceUrl(urlInput.getText().toString(), "HI HELLO")
                    );
                    
                } else {
                    
                    errorLabel.setText("Url to short.");
                    
                }
                
            }
            
        });
        
        
        mainTab.add(errorLabel);
        mainTab.add(testLabel);
        mainTab.add(urlInput);
        mainTab.add(submitUrl);
        
        tabWindow.add("Setup", mainTab);
        tabWindow.add("Extra options", saveTab);
        
        setTitle("Project INJ");
        
        setSize(450, 250);
        
        setMaximumSize(new Dimension(450, 250));
        setMinimumSize(new Dimension(450, 250));
        setResizable(false);
        
        setLocationRelativeTo(null);
        setDefaultCloseOperation(EXIT_ON_CLOSE);
    }
    
    
    public static void main(String[] args) {
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                Inject id = new Inject();
                id.setVisible(true);
            }
        });
    }
}
